$(function () {
    var loading = weui.loading('loading', {
        className: 'custom-classname'
    });
    var result = Model.order.buyerOrder({
        type: 11
    });
    if (!sessionStorage.getItem('hmdj_stopError')) {
        sessionStorage.setItem('hmdj_stopError', true);
    } else {
        if (result.code) {
            Common.fn.formatOutput(result);
            loading.hide();
            return false;
        }
    }
    for (var i = 0; i < result.data.orders.length; i++) {
        var item = '<div class="weui-panel weui-panel_access access-list" data-id="' + result.data.orders[i].orderId + '"><div class="weui-panel__bd"><a href="javascript:;" class="weui-media-box weui-media-box_appmsg"><div class="weui-media-box__hd"><div class="shop-vendor-left"><div class="portrait-block"><img class="portrait-img" src="' + result.data.orders[i].photo + '"></div></div></div><div class="weui-media-box__bd"><h4 class="weui-media-box__title"><label class="vendor-level fans-grade text-1-2">v' + result.data.orders[i].grade + '</label><span class="pruduct-name">' + result.data.orders[i].nickname + '</span></h4><p class="weui-media-box__desc"><h3 class="text-1-4">' + result.data.orders[i].content + '</h3></p></div><div class="weui-media-box__ft order-price">￥' + result.data.orders[i].price + '</div></a></div></div>';
        $('.order-weui-cells').append(item);
    }
    if (result.data.orders.length == 0) {
        $('.order-weui-cells').append('<p style="text-align: center; color: #666;">暂无订单</p>');
    }
    // 显示信息数量
    for (var i = 0; i < 6; i++) {
        // 有信息
        if (result.data['num' + parseInt(i + 1)] > 0) {
            var item = '<div class="count-icon">' + result.data['num' + parseInt(i + 1)] + '</div>';
            $('.order-tab-navbar a').eq(i).append(item);
        }
    }
    loading.hide();
});

$(document).on('click', '.access-list', function () {
    var orderId = $(this).attr('data-id');
    location.href = 'order_buyer_detail.html?oid=' + orderId;
});